<template>
  <div class="profile-container">
    <div class="user-info">
      <img :src="userInfo.avatar || '/default-avatar.png'" class="avatar">
      <h3>{{ userInfo.username }}</h3>
      <p>{{ userInfo.email }}</p>
    </div>
    <button @click="logout" class="logout-btn">退出登录</button>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const userInfo = ref({
  username: 'user',
  email: 'user@example.com',
  avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=user'
});

// 模拟获取用户信息
onMounted(async () => {
  try {
    // 暂时使用模拟数据，后端ready后可以取消注释下面的代码
    /*
    const token = localStorage.getItem('token');
    const response = await axios.get('http://localhost:8080/api/user/profile', {
      headers: {
        Authorization: `Bearer ${token}`
      }
    });
    userInfo.value = response.data;
    */
  } catch (error) {
    console.error('获取用户信息失败:', error);
  }
});

const logout = async () => {
  // 清除token
  localStorage.removeItem('token');
  // 跳转到登录页面
  await router.push('/login');
};
</script>

<style scoped>
.profile-container {
  max-width: 600px;
  margin: 40px auto;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.user-info {
  text-align: center;
  padding: 20px;
}

.avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin-bottom: 16px;
  border: 3px solid #f0f0f0;
}

.user-info h3 {
  margin: 0;
  color: #333;
  font-size: 20px;
  font-weight: 500;
}

.user-info p {
  margin: 8px 0 0;
  color: #666;
  font-size: 14px;
}

.logout-btn {
  width: 100%;
  padding: 12px;
  margin-top: 20px;
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s ease;
}

.logout-btn:hover {
  background: #ff2222;
  transform: translateY(-1px);
}

.logout-btn:active {
  transform: translateY(0);
}
</style> 